﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam1.Biz;
using MockPrjTeam1.Entity;
using MockPrjTeam1.DAO;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;



namespace MockPrjTeam1.Pages.Views
{
    public partial class ViewSearchContact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var biz = new ContactBiz();

                var results = biz.GetAll();
                grvSearchContact.DataSource = results;
                grvSearchContact.DataBind();
            }
        }

        //private void BindData()
        //{
        //    var biz = new ContactBiz();
        //    var data1 = biz.GetAll();
        //    DataTable data = new DataTable();
        //    data.Columns.Add("FirstName", typeof(string));
        //    data.Columns.Add("MobilePhone", typeof(string));
        //    data.Columns.Add("EmailAddress", typeof(string));
        //    data.Columns.Add("ContactType", typeof(string));
        //    data.Columns.Add("IsActive", typeof(string));
        //    grvSearchContact.DataSource = data;
        //    grvSearchContact.DataBind();
        //}

        protected void btnSearchContact_Click(object sender, EventArgs e)
        {
            var FirstName = Convert.ToString(txtFirstName.Text);
            var SurName = Convert.ToString(txtSurName.Text);

            var biz = new ContactBiz();
            var result = biz.SearchContact(FirstName, SurName);
            grvSearchContact.DataSource = result;
            grvSearchContact.DataBind();


        }

        protected void PageChange(object sender, EventArgs e)
        {
            grvSearchContact.PageIndex++;
            grvSearchContact.DataBind();
        }
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Response.Redirect("../../Pages/Forms/ContactDetail.aspx", false);
        }


        protected void btnEdit_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(GetType(), "id", "getSelectedItem();", true);
           // Response.Redirect("../Forms/ContactDetail.aspx?id={0}", false);
        }

        protected void grvSearchContact_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            var biz = new ContactBiz();

            var results = biz.GetAll();
            grvSearchContact.PageIndex = e.NewPageIndex;
            grvSearchContact.DataSource = results;
            grvSearchContact.DataBind();
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtFirstName.Text = "";
            txtSurName.Text = "";
            grvSearchContact.DataSource = null;
        }

        protected void grvSearchContact_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        public void SelectRadioButton()
        {
            Response.Redirect("../../Pages/Forms/ContactDetail.aspx?id={0}", false);
        }

        //protected void btnSelect_Click(object sender, EventArgs e)
        //{
        //    int id = (int)grvSearchContact.SelectedDataKey.Values["ContactID"];
        //    Response.Redirect(string.Format("../../Pages/Forms/ContactDetail.aspx?id={0}", id));
        //}




    }
}